﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            string com = "server=.;database=Ganme;Integrated Security=true;";
            //创建连接对象
            SqlConnection con = new SqlConnection(com);
            //打开连接
            con.Open();
            //创建对象命令
            string sql = "select * from Ganmes";
            SqlCommand select = new SqlCommand(sql, con);
            //查询

            SqlDataReader der = select.ExecuteReader();
            Console.WriteLine("序号\t游戏名称\t游戏价格\t库存");
            Console.WriteLine();
            while (der.Read()) 
            {
                Console.WriteLine("{0}\t{1}\t{2}\t\t{3}", der["ID"],der["Name"],der["Price"], der["Stock"]);
            }
            //关闭数据库
            der.Close();


            //总金额
            string sql2 = "select sum(Price*Stock) from Ganmes";
            select = new SqlCommand(sql2, con);
            string sum = string.Format("{0:c}",select.ExecuteScalar());
            Console.WriteLine("总金额:{0}元",sum);


        }
    }
}
